package apigateway.project.core.filter.flow;

import apigateway.project.commen.constant.FilterConst;
import apigateway.project.core.aspect.FilterAspect;
import apigateway.project.core.aspect.Order;
import apigateway.project.core.context.GlobalContext;
import apigateway.project.core.filter.Filter;

@FilterAspect(value = FilterConst.FLOW_FILTER_ID,name = FilterConst.FLOW_FILTER_NAME)
@Order(FilterConst.FLOW_FILTER_ORDER)
public class FlowFilter implements Filter {
    @Override
    public void doFilter(GlobalContext ctx) throws Exception {
        /**
         * 如果获取的规则里面没有流控的规则，则不进行流控，直接放行
         */
        if(ctx.getRule().getFlowConfig().getType()==null&&ctx.getRule().getFlowConfig().getCount()==0) {
            return;
        }
        GatewayFLowControlRule flowControlbyServiceRule = new FlowControlbyServiceRule(ctx.getRule().getServiceName());
        flowControlbyServiceRule.doFLowControlFilter();
    }
}
